﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection.Emit;
using System.Reflection;
using System.Threading;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace AutoWrapper
{
    class Program
    {
        static void Main(string[] args)
        {
            AppDomain currentDomain = Thread.GetDomain();
            AssemblyName serviceAssemblyName = new AssemblyName();
            serviceAssemblyName.Name = "ServiceAssembly";
            //动态创建一个程序集           
            AssemblyBuilder serviceAssemblyBuilder = currentDomain.DefineDynamicAssembly(serviceAssemblyName, AssemblyBuilderAccess.Run);

            ModuleBuilder serviceModuleBuilder = serviceAssemblyBuilder.DefineDynamicModule("ServiceModule");

           

            Type[] serviceTypeCandidates = MockServiceTypeFinder.GetServiceTypes();
            foreach (Type type in serviceTypeCandidates)
            {
                Type builtServiceType = RESTWrapper.GetDecoratedServiceType(serviceModuleBuilder, type);
                int port = 80;
                Uri baseAddress = new Uri("http://localhost:" + port++);
                RESTWrapper.OpenService(builtServiceType, baseAddress);
            }

        }
    }
}
